<?php

session_start();
header("Cache-control: private");

$valid_user = $_SESSION['valid_user'];

?>

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=ISO-8859-1">
<title>Ride Detail</title>
<link rel="stylesheet" type="text/css" href="../external.css">
</head>
<body>

<?php 
// 2006-22-12 Changes were made to tighten security. Explicitely declaring post variables and checking isset. Questions can be directed to lforget@statnet.ca

if (!isset($valid_user)) {

echo<<<eof
Are your cookies enabled?<br><br>
Enable cookies and go <a href="javascript:history.go(-1)">back</a>.
</body>
</html>
eof;

exit();

}

include('../dbconnect.php'); 
include("../header.php") ;

$id = $_GET['id'];

$id_post = $_POST['id_post'];

$send_email = $_POST['send_email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$from_email = $_POST['from_email'];
$submit = $_POST['submit'];

if (isset($id)) {
    $sql = "SELECT * FROM local WHERE id=$id";
    $result = mysql_query($sql);
    $myrow = mysql_fetch_array($result);
    
//	$id = $myrow["id"];
	$type = $myrow["type"];
	$orig_city = $myrow["orig_city"];
	$start_time = $myrow["start_time"];
	$dest_city = $myrow["dest_city"];
	$end_time = $myrow["end_time"];
	$date = $myrow["date"];
	list ($year, $month, $day) = explode ("-", $date);
	$date = date("F j, Y", mktime(0,0,0, $month, $day, $year));
	$days_show = $myrow["days_show"];
	//$margin = $myrow["margin"];
	$email = $myrow["email"];
	$phone = $myrow["phone"];
	$name = $myrow["name"];
	$license = $myrow["license"];
	$comments = $myrow["comments"];
	$frequency = $myrow["frequency"];
	$costs = $myrow["costs"];
	$smoker = $myrow["smoker"];
	$interests = $myrow["interests"];
	if ($margin) { $margin_note = " - plus or minus $margin days"; }
	list ($year, $month, $day) = explode ("-", $date);
}
?>
	
	<p>
	<p align="center"><b><a href="editjourney_local.php?id=<?php echo "$id"; ?>">Edit or delete this Trip</a></b>
	<p>
	
	<?php
	if (isset($submit)) {
	 if ($send_email && $id_post && $message) {
		mail($email, $subject, $message, "From: $from_email");
		echo "<h2>Your email has been sent</h2>";
	 }
	 else {
		echo "<h2>An error was encountered and your email was not sent. Try again and contact the <a href=\"mailto: lforget@statnet.ca\">webmaster</a> if this problem persists.</h2>";
	 }
	}
	?>
	
	
	<table align="center" border="0" cellpadding="1" cellspacing="0" width="700" bgcolor="#666633">
      <tr>	
      	<td> 
		
    <table align="center" border="0" cellpadding="3" cellspacing="1" width="100%" bgcolor="#eeeedd">
		<tr><td colspan=2><h1 align="center">Local/Frequent or Commuter Trip Details</h1></td></tr>
      <tr>	
        <td align="right" width="20%">Ride Type:</td> 
        <td><?php 
        if ( ereg("offering",$type) ) { echo "I have a car and am looking for passengers (Driver)";
        } elseif ( ereg("looking",$type) ) {echo "I don't have a car; I'm looking for a ride (Passenger)"; } 
        ?></td>
      </tr>		
      <tr>	
        <td align="right">Starting Point:</td>
        <td><?php echo "$orig_city"; ?></td>
      </tr>		
      <tr>	
        <td align="right">Destination:</td>
        <td><?php echo "$dest_city"; ?></td>
      </tr>		
      <tr>	
        <td align="right">Start Time:</td>
        <td><?php echo "$start_time"; ?></td>
      </tr>		
      <tr>	
        <td align="right">Return Time:</td>
        <td><?php echo "$end_time"; ?></td>
      </tr>
      <tr>	
        <td align="right">Trip Schedule:</td>
        <td><?php echo nl2br($frequency); ?>&nbsp;</td>
      </tr>	
      <tr>	
        <td align="right">Trip Info:</td>
        <td><?php echo nl2br($comments) ?>&nbsp;</td>
      </tr>
      <tr>	
        <td align="right">Sharing Costs:</td>
        <td><?php echo $costs ?>&nbsp;</td>
      </tr>		
      <tr>	
        <td align="right">Name:</td>
        <td><?php echo $name ?>&nbsp;</td>
      </tr>		
      <tr>	
        <td align="right">Phone:</td>
        <td><?php echo $phone ?>&nbsp;</td>
      </tr>		
      <tr>	
        <td align="right">Driving Ability:</td>
        <td><?php echo $license ?>&nbsp;</td>
      </tr>		
      <tr>	
        <td align="right">Smoker:</td>
        <td><?php echo $smoker ?>&nbsp;</td>
      </tr>		
      <tr>	
        <td align="right">Interests:</td>
        <td><?php echo $interests ?>&nbsp;</td>
      </tr>			
      <tr>	
        <td align="right">Valid until:</td>
        <td>Good for <?php echo $days_show ?> days after <?php echo $date ?></td>
      </tr>	
		
    </table>
   			</td>
    	</tr>
   </table>
   
<?php
if ($email) {
?>
    <!-- send an email -->
    <form method="post" name="email" action="<?php echo "$PHP_SELF?id=$id"; ?>" method="post">
	<input type="hidden" name="id_post" value="<?= $id ?>">
	<input type="hidden" name="send_email" value="yes">
	<input type="hidden" name="subject" value="Your trip from <?= $orig_city ?> to <?= $dest_city ?>">
    <table align="center" border="0" cellpadding="4" cellspacing="0" width="600">
      <tr><td colspan=2 align=center><b>Send an email to <?php echo $name ?></b></tr>
      <tr>	
        <td align="right"><b>Message:</b><br>
         Indicate your interest in this trip and your schedule. Include your name and phone number and other relevant information.</td>
        <td><textarea name="message" cols="45" rows="6" wrap="virtual"></textarea></td>
      </tr>
      <tr>	
        <td align="right"><b>Your Email:</b><br>
        We will not give your email to anyone</td>
        <td><input type="text" name="from_email" size="40"></td>
      </tr>
      <tr><td colspan=2 align=center><input type="submit" value="Send Email" name="submit"></td>
    </tr>
   </table>
   </form>
		
<?php
}

include("../footer.php"); 
?>
</html>
